namespace RetailAnalytic.Tools.MGrouping
{
    using Infragistics.Win;
    using Infragistics.Win.UltraWinTree;
    using System;
    using System.Collections;
    using System.Drawing;

    public class NodeData
    {
        public NodeData(UltraTreeNode node) : this(node, -1)
        {
        }

        public NodeData(UltraTreeNode node, int id) : this(node, id, false)
        {
        }

        public NodeData(UltraTreeNode node, int id, bool isItem) : this(node, id, isItem, false)
        {
        }

        public NodeData(UltraTreeNode node, int id, bool isItem, bool isBlocked)
        {
            this.boundSubNodes = new ArrayList();
            this.brother = null;
            this.brotherData = null;
            this.node = node;
            this.id = id;
            this.isItem = isItem;
            this.isBlocked = isBlocked;
            this.brotherData = null;
            this.blockedSubNodes = 0;
            this.updateAppearance();
        }

        public UltraTreeNode CopyNode()
        {
            string text2;
            string text1 = this.node.Text;
            if (this.isItem)
            {
                text2 = this.node.Key;
            }
            else
            {
                text2 = "g" + Common.GroupID.ToString();
                Common.GroupID++;
            }
            UltraTreeNode node1 = new UltraTreeNode(text2, text1);
            NodeData data1 = new NodeData(node1);
            node1.DataKey = data1;
            data1.isItem = this.isItem;
            data1.isBlocked = false;
            data1.brother = this.node;
            data1.brotherData = this;
            this.brother = node1;
            this.brotherData = data1;
            this.IsBlocked = true;
            data1.updateAppearance();
            NodeEnumerator enumerator1 = this.node.Nodes.GetEnumerator();
            try
            {
                while (enumerator1.MoveNext())
                {
                    NodeData data2 = (NodeData) enumerator1.Current.DataKey;
                    node1.Nodes.Add(data2.CopyNode());
                }
            }
            finally
            {
                IDisposable disposable1 = enumerator1 as IDisposable;
                if (disposable1 != null)
                {
                    disposable1.Dispose();
                }
            }
            return node1;
        }

        public void updateAppearance()
        {
            AppearanceBase base1 = this.node.Override.NodeAppearance;
            FontData data1 = base1.FontData;
            if (!this.isItem & !this.isBlocked)
            {
                base1.ForeColor = Color.Black;
                data1.Bold = DefaultableBoolean.True;
                base1.Image = 3;
            }
            else if (this.isItem & !this.isBlocked)
            {
                base1.ForeColor = Color.SteelBlue;
                data1.Bold = DefaultableBoolean.False;
                base1.Image = null;
                this.node.Override.LabelEdit = DefaultableBoolean.False;
            }
            else if (!this.isItem & this.isBlocked)
            {
                base1.ForeColor = Color.Gray;
                data1.Bold = DefaultableBoolean.True;
                base1.Image = 3;
            }
            else if (this.isItem & this.isBlocked)
            {
                base1.ForeColor = Color.Gray;
                data1.Bold = DefaultableBoolean.False;
                base1.Image = null;
            }
        }


        public int BlockedSubNodes
        {
            set
            {
                if ((this.blockedSubNodes > 0) & (value == 0))
                {
                    this.IsBlocked = false;
                }
                else if ((this.blockedSubNodes == 0) & (value > 0))
                {
                    this.IsBlocked = true;
                }
                this.blockedSubNodes = value;
            }
        }

        public int Id
        {
            get
            {
                return this.id;
            }
        }

        public bool IsBlocked
        {
            get
            {
                return this.isBlocked;
            }
            set
            {
                if (this.node.Parent != null)
                {
                    NodeData data1 = (NodeData) this.node.Parent.DataKey;
                    if (!this.isBlocked & value)
                    {
                        data1.BlockedSubNodes = data1.blockedSubNodes + 1;
                    }
                    else if (this.isBlocked & !value)
                    {
                        data1.BlockedSubNodes = data1.blockedSubNodes - 1;
                    }
                    this.isBlocked = value;
                    this.updateAppearance();
                }
            }
        }

        public bool IsGroup
        {
            get
            {
                return !this.isItem;
            }
        }

        public bool IsInitial
        {
            get
            {
                return (this.node.Key[0] == 'h');
            }
        }

        public bool IsItem
        {
            get
            {
                return this.isItem;
            }
            set
            {
                this.isItem = value;
                this.updateAppearance();
            }
        }


        private int blockedSubNodes;
        public ArrayList boundSubNodes;
        private UltraTreeNode brother;
        public NodeData brotherData;
        private int id;
        private bool isBlocked;
        private bool isItem;
        public UltraTreeNode node;
    }
}

